using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace AlphaWebsite.Models
{ 
    public class UserPersonalInformationRepository : IUserPersonalInformationRepository
    {
        AlphaWebsiteContext context = new AlphaWebsiteContext();

        public IQueryable<UserPersonalInformation> All
        {
            get { return context.UserPersonalInformations; }
        }

        public IQueryable<UserPersonalInformation> AllIncluding(params Expression<Func<UserPersonalInformation, object>>[] includeProperties)
        {
            IQueryable<UserPersonalInformation> query = context.UserPersonalInformations;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public UserPersonalInformation Find(System.Guid? id)
        {
            return context.UserPersonalInformations.Find(id);
        }

        public void InsertOrUpdate(UserPersonalInformation userpersonalinformation)
        {
            if (userpersonalinformation.UserID == default(System.Guid?)) {
                // New entity
                context.UserPersonalInformations.Add(userpersonalinformation);
            } else {
                // Existing entity
                context.Entry(userpersonalinformation).State = EntityState.Modified;
            }
        }

        public void Delete(System.Guid? id)
        {
            var userpersonalinformation = context.UserPersonalInformations.Find(id);
            context.UserPersonalInformations.Remove(userpersonalinformation);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose() 
        {
            context.Dispose();
        }
    }

    public interface IUserPersonalInformationRepository : IDisposable
    {
        IQueryable<UserPersonalInformation> All { get; }
        IQueryable<UserPersonalInformation> AllIncluding(params Expression<Func<UserPersonalInformation, object>>[] includeProperties);
        UserPersonalInformation Find(System.Guid? id);
        void InsertOrUpdate(UserPersonalInformation userpersonalinformation);
        void Delete(System.Guid? id);
        void Save();
    }
}